﻿/***************************************************************
 * Name:      MinesweeperMain.h
 * Purpose:   Defines Application Frame
 * Author:    PhoenixWright (cbx945+dev@gmail.com)
 * Created:   2011-04-30
 * Copyright: PhoenixWright (http://www.itcbx.com)
 * License:
 **************************************************************/

#ifndef MINESWEEPERMAIN_H
#define MINESWEEPERMAIN_H

#ifndef WX_PRECOMP
    #include <wx/wx.h>
#endif

#include "MinesweeperApp.h"
#include "Mine.h"

class MinesweeperFrame: public wxFrame
{
    public:
        MinesweeperFrame(wxFrame *frame, const wxString& title);
        ~MinesweeperFrame() {}
    private:
        void OnClose(wxCloseEvent& event);
        void OnQuit(wxCommandEvent& event);
        void OnAbout(wxCommandEvent& event);
        void OnPaint(wxPaintEvent &event);
        void OnRightDown(wxMouseEvent &event);
        void OnLeftDown(wxMouseEvent &event);
        void OnLeftUp(wxMouseEvent &event);
        void OnMiddleDown(wxMouseEvent &event);
        void OnMotion(wxMouseEvent &event);
        void OnSize(wxSizeEvent &event);

        void OnNewGame(wxCommandEvent& event);
        DECLARE_EVENT_TABLE()

    private:
        void InitSources();
        void AdjustPosition(int x, int y, int &x1, int &y1, int &x2, int &y2);
        int AdjustKnownPosition(int row, int col);
        int AdjustUnknownPosition(int row, int col);
        bool IsValid(int row, int col);
        void RefreshMineMap(wxDC &dc);
        void NewGame(bool _restart = false);
    private:

        /**
         * 扫雷逻辑操作类.
         * @see Mine
         */
        Mine mineLogic;
        // 缩放比例因子
        double scaleX, scaleY;

        // 扫雷主界面起始位置
        wxPoint ptGame;

        wxSize defaultClientSize;

        //扫雷地图图片资源
        wxImage greenUnknown[720], greenKnown[720];
        wxImage blueUnknown[720], blueknown[720];
        wxImage number[9];
        wxImage mine;
        wxImage *unknown, *known;

        wxImage mark, question;

        wxPoint mousePrevPosition;
};


#endif // MINESWEEPERMAIN_H
